package team.hyznrj.studentsys.dao.mapper.provider;

import org.apache.ibatis.jdbc.SQL;
import team.hyznrj.studentsys.form.CourseConditionalForm;

/**
 * @author ReMidDream
 * @date 2018-03-27 22:35
 **/
public class SelectSqlProvider {

    private final String COURSEACHIEVEMENT = "id,student_id,course_title,course_credit,remarks,convert_mark,course_grade_point,curriculum_nature,academic_year,school_term";

    public String findByCourseAchievementForm(final CourseConditionalForm courseConditionalForm){
        return new SQL(){{
            SELECT(COURSEACHIEVEMENT);
            FROM("course_achievement");
            WHERE("status=1");
            if(courseConditionalForm.getStudentId() != null){
                WHERE("student_id in (#{studentId})");
            }
            if(courseConditionalForm.getCourseTitle() != null){
                WHERE("course_title=#{courseTitle}");
            }
            if(courseConditionalForm.getCourseCredit() != null){
                WHERE("course_credit=#{courseCredit}");
            }
            if(courseConditionalForm.getConvertMark() != null){
                WHERE("convert_mark=#{convertMark}");
            }
            if(courseConditionalForm.getCurriculumNature() != null){
                WHERE("curriculum_nature=#{curriculumNature}");
            }
            if(courseConditionalForm.getAcademicYear() != null){
                WHERE("academic_year=#{academicYear}");
            }
            if(courseConditionalForm.getSchoolTerm() != null){
                WHERE("school_term=#{schoolTerm}");
            }
        }}.toString();
    }
}
